Imports System.Diagnostics
Imports System.IO

Public Class PhoenixTraceListener
    Inherits TraceListener

    Public Sub New(ByVal fileName As String)
        mFileName = fileName
    End Sub


    Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
        If Not mWriter Is Nothing Then
            CType(mWriter, IDisposable).Dispose()
        End If
    End Sub

    Public Overrides Sub Flush()
        If Not mWriter Is Nothing Then
            Try
                mWriter.Flush()
            Catch
            End Try
        End If
    End Sub

    Public Overloads Overrides Sub Write(ByVal message As String)
        Try
            Writer.Write(message)
        Catch
        End Try
    End Sub

    Public Overloads Overrides Sub WriteLine(ByVal message As String)
        Try
            Writer.WriteLine(message)
        Catch
        End Try
    End Sub


    Private ReadOnly Property Writer() As StreamWriter
        Get
            If mWriter Is Nothing Then
                Try
                    mWriter = New StreamWriter(mFileName)
                Catch ex As Exception

                End Try
            End If
            Return mWriter
        End Get
    End Property


    Private mFileName As String
    Private mWriter As StreamWriter
End Class
